package com.office.service;

import com.office.bean.TDepart;
import javafx.scene.input.DataFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Departtest {
    @Autowired
    DepartService departService;

    @Test
    public void insert () throws ParseException {
        TDepart tDepart  = new TDepart();

        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date();
        String nowdate = date.format(date1);

        tDepart.setCreatetime(nowdate);
        tDepart.setName("教育部");
        int i = departService.addDepart(tDepart);
        System.out.println(i>0?"教育部新增成功":"插入失败");
    }
    @Test
    public void insertmoredate(){
        TDepart tDepart  = new TDepart();

        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date();
        String nowdate = date.format(date1);

        for (int i=0;i<100;i++){
            tDepart.setCreatetime(nowdate);
            tDepart.setName("教育部"+i);
            departService.addDepart(tDepart);
        }

    }

    @Test
    public void findallcountpage(){
        long findallcount = departService.findallcount();
        System.out.println(findallcount);
    }

    @Test
    public void pagetest(){
        long pagestart=2;
        long pagesize=5;
        long findallcount = departService.findallcount();
        System.out.println("总记录数："+findallcount);
        System.out.println("当前页码："+pagestart);
        System.out.println("当前页码大小："+pagesize);
        System.out.println("总页数"+((findallcount%pagesize)==0?(findallcount/pagesize):(findallcount/pagesize+1)));
        HashMap<String, Object> map = new HashMap<>();
        map.put("pageIndex",(pagestart-1)*pagesize);
        map.put("pagesize",pagesize);
        List<TDepart> findpagecount = departService.findpagecount(map);
        for (TDepart tDepart : findpagecount) {
            System.out.println(tDepart);
        }
    }
    @Test
    public void delecttest(){
        boolean delectdepart = departService.delectdepart(2);
        System.out.println(delectdepart);
    }
}
